//
//  HEAIMsgModel.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/22.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEAIMsgModel.h"
#import "HEGuessTextCell.h"

#import "HEDiagnosisCardCell.h"
#import "HEAIUserTextCell.h"
#import "HEDiseaseItemCell.h"
#import "HEAIMsgTextCell.h"
#import "HEAIMissonCell.h"
#import "HEAISingleQuestionCell.h"
#import "HEAIQuestionRadioCell.h"
#import "HEAIEndReportCell.h"
#import "HEAIEndNoticeCell.h"
#import "HEAIMultiQuestionCell.h"
#import "HEAIMultiSelectCell.h"


@interface HEAIMsgModel ()

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation HEAIMsgModel

+ (NSDictionary *)mj_objectClassInArray{
    return @{@"subDataArr" : [HEAISubItemModel class]
    };
}

// YYModel 对这些关键字不做解析
+ (NSArray *)modelPropertyBlacklist {
    return @[@"tableView" ];
}

- (NSMutableArray *)subDataArr {
  if (_subDataArr == nil) {
      _subDataArr = [[NSMutableArray alloc] init];
  }
  
  return _subDataArr;
}

- (CGFloat)getTableHeight:(UITableView *)tableView {
    _tableView = tableView;
    if (!_subTableHeight) {
        CGFloat tableViewHeight = 0;
        int i = 0;
        for (HEAISubItemModel *subItem in _subDataArr) {
            
            NSIndexPath * pa = [NSIndexPath indexPathForRow:i inSection:0];
          CGFloat cellHeight = [tableView fd_heightForCellWithIdentifier: NSStringFromClass([self getSubCellClass]) cacheByIndexPath:pa configuration:^(MCTableBaseCell *cell) {
              [cell configCellWithModel: subItem];
                  }];
          tableViewHeight += cellHeight;
            i++;
        }
        _subTableHeight = tableViewHeight;
    }
    return _subTableHeight;
}

- (Class)getCellClass {
    switch (_type) {
        case HEAIMsgTypeDiesaeConsult:
            return HEDiagnosisCardCell.class;
        case HEAIMsgTypeUserText:
            return HEAIUserTextCell.class;
        case HEAIMsgTypeAIText:
            return HEAIMsgTextCell.class;
        case HEAIMsgTypeAIMisson:
            return HEAIMissonCell.class;
        case HEAIMsgTypeAISingleQuestion:
            return HEAISingleQuestionCell.class;
        case HEAIMsgTypeAIReport:
            return HEAIEndReportCell.class;
        case HEAIMsgTypeAIFinish:
            return HEAIEndNoticeCell.class;
        case HEAIMsgTypeAIMultiQuestion:
            return HEAIMultiQuestionCell.class;
            
            
        default:
            break;
    }
    return nil;
}

- (Class)getSubCellClass {
    switch (_type) {
        case HEAIMsgTypeDiesaeConsult:
            return HEDiseaseItemCell.class;
            
        case HEAIMsgTypeAIMisson:
            return HEGuessTextCell.class;
            
        case HEAIMsgTypeAISingleQuestion:
            return HEAIQuestionRadioCell.class;
            
        case HEAIMsgTypeAIMultiQuestion:
            return HEAIMultiSelectCell.class;
            
        default:
            break;
    }
    return nil;
}

- (CGFloat)contentWidth {
    if (!_contentWidth) {
        
        CGFloat warp = KScreenWidth - (15 + 50 + 15 + 15 + 50 + 5) - 15 * 2;
        _contentWidth = ceilf([_content widthForFont:DYFont(16)]);
        if (_contentWidth > warp) {
            _contentWidth = warp;
        }
    }
    return _contentWidth;
}

- (void)refreshData {
    [_tableView reloadData];
}

@end
